home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Draw / Include / Shapes.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  13.3 KB  |  447 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Shapes.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef SHAPES_H
  14. #define SHAPES_H
  15.  
  16. #ifndef DRAWFRAME_H
  17. #include "DrawFrame.h"
  18. #endif
  19.  
  20. #ifndef DRAWPROXY_H
  21. #include "DrawProxy.h"
  22. #endif
  23.  
  24. // ----- Graphic Includes -----
  25.  
  26. #ifndef FWLINSHP_H
  27. #include "FWLinShp.h"
  28. #endif
  29.  
  30. #ifndef FWARCSHP_H
  31. #include "FWArcShp.h"
  32. #endif
  33.  
  34. #ifndef FWRECSHP_H
  35. #include "FWRecShp.h"
  36. #endif
  37.  
  38. #ifndef FWRRCSHP_H
  39. #include "FWRRcShp.h"
  40. #endif
  41.  
  42. #ifndef FWOVLSHP_H
  43. #include "FWOvlShp.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef _PLFMDEF_
  49. #include <PlfmDef.h>
  50. #endif
  51.  
  52. // ----- Mac Includes -----
  53.  
  54. #ifndef __TYPES__
  55. #include <Types.h>
  56. #endif
  57.  
  58. //==============================================================================
  59. // Forward Declarations
  60. //==============================================================================
  61.  
  62. class FW_CEmbeddingFrame;
  63. class XMPFrame;
  64. class XMPShape;
  65. class CDrawPart;
  66. class CDrawPublishLink;
  67. class CDrawSubscribLink;
  68.  
  69. //==============================================================================
  70. // Constants
  71. //==============================================================================
  72.  
  73. enum ShapeType {
  74.     kLineShape = 1,
  75.     kRectShape = 2,
  76.     kOvalShape = 3,
  77.     kRRectShape = 4,
  78.     kProxyShape = 5
  79. };
  80.  
  81. const unsigned short kFrameOnly = 1;
  82. const unsigned short kFillOnly = 2;
  83. const unsigned short kFrameFill = 3;
  84.  
  85. //==============================================================================
  86. // class CBaseShape
  87. //==============================================================================
  88.  
  89. class CBaseShape
  90. {
  91. public:
  92.     virtual ~CBaseShape();
  93.  
  94.     virtual void Removed();
  95.     
  96.     // ----- Drawing -----
  97.     virtual void         DrawShape(FW_CGraphicContext* gc) = 0;
  98.     void                DrawShapeHandles(FW_CFacet* facet, FW_Boolean turnOn);
  99.     void                DrawHandle(short whichHandle);
  100.     
  101.     // ----- Shape setting -----
  102.     virtual void        SetShapeProperties(FW_ShapeFills shapeFills, FW_CInk ink, FW_CStyle style);
  103.     virtual void        RenderShape(FW_CGraphicContext* gc);
  104.     virtual XMPCoordinate GetPenSize() const;
  105.         
  106.     // ----- Selection -----
  107.     virtual FW_Boolean    HitTest(FW_CGraphicContext* gc, const FW_CPoint& mouse, XMPEventData event) const = 0;
  108.     FW_Boolean            InSelectionRect(const FW_CRect& rect) const;
  109.     
  110.     short            WhichHandle(FW_CFacet* facet, const FW_CPoint& mouse) const;
  111.     
  112.     void                 CalcHandleRect(short whichHandle, FW_CRect* handleRect) const;
  113.  
  114.     virtual void        SelectShape(FW_Boolean state);
  115.     FW_Boolean            IsSelected() const
  116.                             {return fSelected;}
  117.  
  118.     // ----- Creation -----
  119.     FW_Boolean             Track(FW_CGraphicContext* gc, FW_CStyle trackStyle, const FW_CPoint& anchorPoint, XMPEventData event);
  120.     virtual void         TrackFeedback(FW_CGraphicContext* gc, const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint, FW_Boolean erase);
  121.     virtual void         SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint) = 0;
  122.  
  123.     // ----- Drag -----
  124.     virtual void        OffsetShape(XMPCoordinate xDelta, XMPCoordinate yDelta) = 0;
  125.     
  126.     // ----- Resize -----
  127.     virtual void        ResizeFeedback(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& originalRect, const FW_CRect& mapRect) = 0;
  128.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint* center) const = 0;
  129.     virtual void        MapShape(const FW_CRect& srcRect, const FW_CRect& dstRect) = 0;
  130.     
  131.     virtual void        GetUpdateShape(XMPShape *updateShape) const = 0;
  132.     virtual void        GetDragRgn(FW_CGraphicContext* gc, FW_PlatformRegion dragRgn) = 0;
  133.     virtual XMPShape*    GetClipShape(FW_CGraphicContext* gc) = 0;
  134.     virtual FW_CRect    GetBoundingBox() const = 0;
  135.     
  136.     // ----- z-Order -----
  137.     virtual void         MovedAfter(CBaseShape* shape);
  138.     virtual void         MovedBefore(CBaseShape* shape);
  139.     virtual void         MovedFirst();
  140.     virtual void         MovedLast();
  141.     
  142.     // ----- Persistence -----
  143.     virtual void         Flatten(XMPStorageUnit* storage);
  144.     virtual void         Unflatten(CDrawPart* drawPart, XMPStorageUnit* storage);
  145.     virtual void        CloneTo(XMPStorageUnit* storageUnit, FW_CFrame* commandFrame, XMPCloneKind cloneKind);
  146.     virtual void        CloneFrom(CDrawPart* drawPart, XMPStorageUnit* storage, XMPCloneKind cloneKind);
  147.     
  148.     // ----- Cache -----
  149.     void                ClearCache();
  150.     
  151.     // ----- Linking -----
  152.     void                SetPublishLink(CDrawPublishLink *publishLink)
  153.                             {fPublishLink = publishLink;}
  154.     CDrawPublishLink*    GetPublishLink() const
  155.                             {return fPublishLink;}
  156.     FW_Boolean            IsPublished() const
  157.                             {return fPublishLink != NULL;}
  158.                             
  159.     void                SetSubscribLink(CDrawSubscribLink *subscribLink)
  160.                             {fSubscribLink = subscribLink;}
  161.     CDrawSubscribLink*    GetSubscribLink() const
  162.                             {return fSubscribLink;}
  163.     FW_Boolean            IsSubscribed() const
  164.                             {return fSubscribLink != NULL;}
  165.                             
  166.     // ----- Getters/Setters -----
  167.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  168.     virtual FW_Boolean IsFrozen() const;
  169.  
  170.     void                SetPenStyle(FW_CStyle penStyle);
  171.     void                SetBrushStyle(FW_CStyle brushStyle)
  172.                             {fBrushStyle = brushStyle;}
  173.     void                SetPenInk(FW_CInk penInk)
  174.                             {fPenInk = penInk;}
  175.     void                SetBrushInk(FW_CInk brushInk)
  176.                             {fBrushInk = brushInk;}
  177.  
  178.     FW_CStyle            GetPenStyle()
  179.                             {return fPenStyle;}
  180.     FW_CStyle            GetBrushStyle()
  181.                             {return fBrushStyle;}
  182.     FW_CInk                GetPenInk()
  183.                             {return fPenInk;}
  184.     FW_CInk                GetBrushInk()
  185.                             {return fBrushInk;}
  186.     
  187.     FW_Boolean            HasFillStyle() const
  188.                             {return (fFrameFill & kFillOnly) != 0;}
  189.     FW_Boolean            FillOnly() const
  190.                             {return fFrameFill == kFillOnly;}
  191.     FW_Boolean            HasFrameStyle() const
  192.                             {return (fFrameFill & kFrameOnly) != 0;}
  193.     FW_Boolean            FrameOnly() const
  194.                             {return fFrameFill == kFrameOnly;}
  195.     FW_Boolean            HasFrameAndFillStyle() const
  196.                             {return (fFrameFill == kFrameFill);}
  197.                             
  198.     void                SetFrameFillStyle(unsigned short style);
  199.     unsigned short            GetFrameFillStyle() const
  200.                             {return fFrameFill;}
  201.                             
  202.     short            GetNumberOfHandles() const
  203.                             {return fNumberOfHandles;}
  204.     ShapeType            GetShapeType() const
  205.                             {return (ShapeType)fShapeType;}
  206. protected:
  207.     CBaseShape(short numberOfHandles, unsigned short shapeType);
  208.     
  209. protected:
  210.     XMPShape*            fClipShape;
  211.     FW_CShape            fBaseShape;
  212.         
  213. private:
  214.     unsigned short    fShapeType;
  215.     
  216.     FW_Boolean            fSelected;
  217.     short                fNumberOfHandles;
  218.     CDrawPublishLink*    fPublishLink;
  219.     CDrawSubscribLink*    fSubscribLink;
  220.     
  221.     FW_CInk                fPenInk;
  222.     FW_CInk                fBrushInk;
  223.     FW_CStyle            fPenStyle;
  224.     FW_CStyle            fBrushStyle;
  225.     
  226.     unsigned short    fFrameFill;
  227.     
  228. };
  229.  
  230. //==============================================================================
  231. // class CLineShape
  232. //==============================================================================
  233.  
  234. class CLineShape : public CBaseShape
  235. {
  236. public:
  237.     CLineShape();
  238.     virtual ~CLineShape();
  239.         
  240.     // ----- Geometry
  241.     virtual void        SetShapeGeometry(const FW_CPoint& anchorPoint,  const FW_CPoint& currentPoint);
  242.     virtual void        GetUpdateShape(XMPShape *updateShape) const;
  243.     virtual void        GetDragRgn(FW_CGraphicContext* gc, FW_PlatformRegion dragRgn);
  244.     virtual XMPShape*    GetClipShape(FW_CGraphicContext* gc);
  245.     virtual FW_CRect    GetBoundingBox() const;
  246.     
  247.     FW_CPoint            GetLineStart() const
  248.                             {return fShape->GetLineStart();}
  249.     FW_CPoint            GetLineEnd() const
  250.                             {return fShape->GetLineEnd();}
  251.                             
  252.     // ----- Selection
  253.     virtual FW_Boolean    HitTest(FW_CGraphicContext* gc, const FW_CPoint& mouse, XMPEventData event) const;
  254.     
  255.     // ----- Dragging
  256.     virtual void        OffsetShape(XMPCoordinate xDelta, XMPCoordinate yDelta);
  257.  
  258.     // ----- Resize
  259.     virtual void        ResizeFeedback(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& originalRect, const FW_CRect& mapRect);
  260.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint* center) const;
  261.     virtual void        MapShape(const FW_CRect& srcRect, const FW_CRect& dstRect);
  262.  
  263.     // ----- Drawing
  264.     virtual void         DrawShape(FW_CGraphicContext* gc);
  265.  
  266.     // ----- Persistence
  267.     virtual void         Flatten(XMPStorageUnit* storage);
  268.     virtual void         Unflatten(CDrawPart* drawPart, XMPStorageUnit* storage);
  269.  
  270. private:
  271.     void                 OutlineShape(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, 
  272.                                      const FW_CPoint& pt1, const FW_CPoint& pt2);
  273.  
  274. private:
  275.     FW_CLineShape        fShape;
  276. };
  277.  
  278. //==============================================================================
  279. // class CBoundedShape
  280. //==============================================================================
  281.  
  282. class CBoundedShape : public CBaseShape
  283. {
  284. public:
  285.     virtual ~CBoundedShape();
  286.  
  287.     // ----- Drawing
  288.     virtual void         DrawShape(FW_CGraphicContext* gc);
  289.  
  290.     // ----- Geometry
  291.     virtual void        SetShapeGeometry(const FW_CPoint& anchorPoint,  const FW_CPoint& currentPoint);
  292.     virtual void        GetUpdateShape(XMPShape *updateShape) const;
  293.     virtual void        GetDragRgn(FW_CGraphicContext* gc, FW_PlatformRegion dragRgn);
  294.     virtual XMPShape*    GetClipShape(FW_CGraphicContext* gc);
  295.     virtual void        SetBoundingBox(const FW_CRect& bounds) = 0;
  296.     
  297.     // ----- Hit Test
  298.     virtual FW_Boolean    HitTest(FW_CGraphicContext* gc, const FW_CPoint& mouse, XMPEventData event) const;
  299.     
  300.     // ----- Dragging
  301.     virtual void        OffsetShape(XMPCoordinate xDelta, XMPCoordinate yDelta);
  302.  
  303.     // ----- Resize
  304.     virtual void        ResizeFeedback(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& originalRect, const FW_CRect& mapRect);
  305.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint* center) const;
  306.     virtual void        MapShape(const FW_CRect& srcRect, const FW_CRect& dstRect);
  307.  
  308.     // ----- Persistence
  309.     virtual void         Flatten(XMPStorageUnit* storage);
  310.     virtual void         Unflatten(CDrawPart* drawPart, XMPStorageUnit* storage);
  311.  
  312. protected:
  313.     CBoundedShape(unsigned short shapeType);
  314.  
  315. private:
  316.     virtual void         OutlineShape(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& rect) = 0;
  317.     void                CalcRect(const FW_CPoint& anchorPoint, const FW_CPoint& endPoint, FW_CRect* rect);
  318.  
  319. private:
  320.     FW_CRect            fRect;
  321. };
  322.  
  323. //==============================================================================
  324. // class CRectShape
  325. //==============================================================================
  326.  
  327. class CRectShape : public CBoundedShape
  328. {
  329. public:
  330.     CRectShape();
  331.     virtual ~CRectShape();
  332.     
  333.     // ----- Geometry
  334.     virtual FW_CRect    GetBoundingBox() const;
  335.     virtual void        SetBoundingBox(const FW_CRect& bounds);
  336.             
  337. protected:
  338.     CRectShape(unsigned short shapeType);
  339.  
  340. private:
  341.     virtual void         OutlineShape(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& rect);
  342.  
  343. private:
  344.     FW_CRectShape        fShape;
  345. };
  346.  
  347. //==============================================================================
  348. // class COvalShape
  349. //==============================================================================
  350.  
  351. class COvalShape : public CBoundedShape
  352. {
  353. public:
  354.     COvalShape();
  355.     virtual ~COvalShape();
  356.     
  357.     // ----- Geometry
  358.     virtual FW_CRect    GetBoundingBox() const;
  359.     virtual void        SetBoundingBox(const FW_CRect& bounds);
  360.     
  361.     // ----- Selection
  362.     virtual FW_Boolean    HitTest(FW_CGraphicContext* gc, const FW_CPoint& mouse, XMPEventData event) const;
  363.     
  364. private:
  365.     virtual void        OutlineShape(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& rect);
  366.  
  367. private:
  368.     FW_COvalShape        fShape;
  369. };
  370.  
  371. //==============================================================================
  372. // class CRoundRectShape
  373. //==============================================================================
  374.  
  375. class CRoundRectShape : public CBoundedShape
  376. {
  377. public:
  378.     CRoundRectShape();
  379.     virtual ~CRoundRectShape();
  380.     
  381.     // ----- Geometry
  382.     virtual FW_CRect    GetBoundingBox() const;
  383.     virtual void        SetBoundingBox(const FW_CRect& bounds);
  384.  
  385.     virtual void        SetShapeGeometry(const FW_CPoint& anchorPoint,  const FW_CPoint& currentPoint);
  386.     
  387. private:
  388.     virtual void        OutlineShape(FW_CGraphicContext* gc, FW_CInk ink, FW_CStyle style, const FW_CRect& rect);
  389.  
  390. private:
  391.     FW_CRoundRectShape        fShape;
  392. };
  393.  
  394. //==============================================================================
  395. // class CProxyShape
  396. //==============================================================================
  397.  
  398. class CProxyShape : public CRectShape
  399. {
  400. public:
  401.     CProxyShape(const FW_CRect& rect);
  402.     CProxyShape();
  403.     virtual ~CProxyShape();
  404.     virtual void Removed();
  405.         
  406.     virtual void         DrawShape(FW_CGraphicContext* gc);
  407.  
  408.     virtual FW_Boolean    HitTest(FW_CGraphicContext* gc, const FW_CPoint& mouse, XMPEventData event) const;
  409.     
  410.     virtual void        OffsetShape(XMPCoordinate xDelta, XMPCoordinate yDelta);
  411.     virtual void        MapShape(const FW_CRect& srcRect, const FW_CRect& dstRect);
  412.     
  413.     virtual void         SelectShape(FW_Boolean state);
  414.  
  415.     void                ProxyShapeChanged(const FW_CRect& rect);
  416.     
  417.     CDrawProxyRun*        GetProxyRun() const
  418.                             {return fProxyRun;}
  419.     void                SetProxyRun(CDrawProxyRun* proxyRun)
  420.                             {fProxyRun = proxyRun;}
  421.                                 
  422.     // ----- Persistence
  423.     virtual void         Flatten(XMPStorageUnit* storage);
  424.     virtual void         Unflatten(CDrawPart* drawPart, XMPStorageUnit* storage);
  425.     virtual void        CloneTo(XMPStorageUnit* storageUnit, 
  426.                                   FW_CFrame* commandFrame, 
  427.                                   XMPCloneKind cloneKind);
  428.     virtual void        CloneFrom(CDrawPart* drawPart, 
  429.                                   XMPStorageUnit* storage, 
  430.                                   XMPCloneKind cloneKind);
  431.  
  432.     // ----- z-Order -----
  433.     virtual void         MovedAfter(CBaseShape* shape);
  434.     virtual void         MovedBefore(CBaseShape* shape);
  435.     virtual void         MovedFirst();
  436.     virtual void         MovedLast();
  437.     
  438.     // ----- Frozen -----
  439.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  440.     virtual FW_Boolean IsFrozen() const;
  441.  
  442. private:
  443.     CDrawProxyRun        *fProxyRun;
  444.     FW_Boolean            fFrozen;
  445.  
  446. };
  447. #endif